package com.ipet.item.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ipet.item.mapper.SPUMapper;
import com.ipet.item.pojo.SPU;
import com.ipet.item.service.SPUService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class SPUServiceImpl extends ServiceImpl<SPUMapper , SPU> implements SPUService {
    @Override
    public PageInfo<SPU> findAllSPU(Integer pageNo, Integer pageSize) {
        PageHelper.startPage(pageNo , pageSize);
        List<SPU> spuList = this.baseMapper.findAllSpu();
        return new PageInfo<>(spuList);
    }

    @Override
    public PageInfo<SPU> findSPUByTitle(String title, Integer pageNo, Integer pageSize) {
        PageHelper.startPage(pageNo , pageSize);
        List<SPU> spuList = this.baseMapper.findSPUByTitle(title);
        return new PageInfo<>(spuList);
    }

    @Override
    public PageInfo<SPU> findSPUBySaleable(Integer saleable, Integer pageNo, Integer pageSize) {
        PageHelper.startPage(pageNo , pageSize);
        List<SPU> spuList = this.baseMapper.findSPUBySaleable(saleable);
        return new PageInfo<>(spuList);
    }
    //    批量上架下架商品
    @Override
    public Integer updateSaleable(Integer saleable, List<String> list) {
        return this.baseMapper.saleableBatch(saleable, list);
    }
//批量删除商品
    @Override
    public Integer deleteSPUBatch(List<String> list) {
        return this.baseMapper.deleteSpuBatch(list);
    }


}
